/*
 *接口编写处...
*如果接口需要做Action的权限验证，请在Action上使用属性
*如: [ApiActionPermission("InductionFurnaceReplenishment",Enums.ActionPermissionOptions.Search)]
 */
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using Mercury.Entity.DomainModels;
using Mercury.Business.IServices;
using Mercury.Core.Utilities;
using Mercury.Core.Common;
using Mercury.Business.IRepositories;
using Mercury.Core.Enums;
using Mercury.Core.Filters;
using Mercury.WebApi.Controllers.Hubs;

namespace Mercury.Business.Controllers
{
    [Route("api/IFR")]
    public partial class InductionFurnaceReplenishmentController
    {
        private readonly IInductionFurnaceReplenishmentService _service;//访问业务代码
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly IInductionFurnaceReplenishmentRepository _repository;
        private readonly HomePageMessage _message;
        //IHubContext<HomePageMessageHub> _hub;

        [ActivatorUtilitiesConstructor]
        public InductionFurnaceReplenishmentController(
            IInductionFurnaceReplenishmentService service,
            IInductionFurnaceReplenishmentRepository repository,
            IHttpContextAccessor httpContextAccessor ,
            HomePageMessage message 
         
        )
        : base(service)
        {
            //_hub.Clients.All.se
            _message = message;
            _service = service;
            _repository = repository;
            _httpContextAccessor = httpContextAccessor;
        }


        [Route("CreateBill/{heat}/{orderNo}"), HttpGet]
        [ApiActionPermission(ActionPermissionOptions.Ingredient2)]
        public async Task<WebResponseContent> GetMaterialsAmount(string orderNo,int heat)
        {
            if (heat == 0)
            {
                var result = await orderNo.ReplenishmentListCalculation(_repository, _message.SendNoticeAction);
                return new WebResponseContent()
                {
                    Status = result.Item1,
                    Message = result.Item1 ? "补料成功，请前往补料单查看补料结果！" : result.Item2,
                    Data = result.Item3
                };
            }
            else
            {
                var result = await orderNo.ReplenishmentOnProcessing(_repository, _message.SendNoticeAction);
                return new WebResponseContent()
                {
                    Status = result.Item1,
                    Message = result.Item1 ? "补料成功，请前往补料单查看补料结果！" : result.Item2,
                    Data = result.Item3
                };
            }

        }
    }
}
